package com.example.smartcitymovie;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.smartcitymovie.adapter.RecycleViewAdapter;
import com.example.smartcitymovie.bean.MovieListBean;
import com.example.smartcitymovie.dataRepo.ApiData;
import com.example.smartcitymovie.databinding.FragmentMovieBinding;
import com.example.smartcitymovie.ui.movie.MovieMessageActivity;
import com.example.smartcitymovie.utils.OkHttpUtils;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;


public class MovieFragment extends Fragment {

    FragmentMovieBinding binding;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        binding = FragmentMovieBinding.inflate(inflater);
        initView();
        return binding.getRoot();
    }

    private void initView() {
        MovieListBean movieListBean = ApiData.getMovieListBean();
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    binding.RVShowMovies.setLinearLayoutManager(LinearLayout.VERTICAL);
                    binding.RVShowMovies.setAdapter(movieListBean.getRows(),R.layout.movie_list_item_layout_style_two);
                    binding.RVShowMovies.getBaseAdapter().setOnPartRecycleViewItemClickListener(new RecycleViewAdapter.OnPartRecycleViewItemClickListener() {
                        @Override
                        public void onPartRecycleViewItemClickListener(View view, int position) {
                            Intent intent = new Intent(getActivity(), MovieMessageActivity.class);
                            intent.putExtra("id",movieListBean.getRows().get(position).getId());
                            startActivity(intent);
                        }
                    },R.id.btn_BuyMovie);
                }
            });
    }
}